package com.sx.micowell.framework.tools;

import android.annotation.SuppressLint;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author: YY
 * @time: 2021/5/28
 * @describe 时间格式转换工具类
 */
@SuppressLint("SimpleDateFormat")
public class DateUtils {

    public static final String DATE_HOUR_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static final String DATE_HOUR = "HH:mm:ss";

    public static String getDateToString(long milSecond, String pattern) {
        Date date = new Date(milSecond);
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        return format.format(date);
    }

    @SuppressLint("DefaultLocale")
    public static String secToTime(long time) {
        String hh = "";
        String mm = "";
        String ss = "";

        long ti = time / 1000;
        hh = String.format("%02d", ti / 3600);

        long mm1 = (ti - Long.parseLong(hh) * 3600) / 60;
        mm = String.format("%02d", mm1);

        long ss1 = ti - Long.parseLong(hh) * 3600 - Long.parseLong(mm) * 60;
        ss = String.format("%02d", ss1);

        return hh + ":" + mm + ":" + ss;

    }


    public static long getLongFromString(String dateTime) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");//24小时制
            return simpleDateFormat.parse(dateTime).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

}
